home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group94a.txt / 000178_icon-group-sender _Thu Jun 16 21:43:30 1994.msg < prev    next >
Internet Message Format  |  1994-08-19  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Fri, 17 Jun 1994 08:06:39 MST
  2. Date: Thu, 16 Jun 1994 21:43:30 MST
  3. From: "Clinton L. Jeffery" <cjeffery>
  4. Message-Id: <199406170443.AA15757@cheltenham.cs.arizona.edu>
  5. To: eric@star-semi.com
  6. Cc: icon-group@cs.arizona.edu
  7. In-Reply-To: Eric Armstrong's message of Thu, 16 Jun 94 12:27:04 PDT <9406161927.AA07961@star-semi.com>
  8. Subject: Re: booleans, enumerations, globals
  9. Status: R
  10. Errors-To: icon-group-errors@cs.arizona.edu
  11.  
  12.    [Eric writes:]
  13.    I'm wondering what idioms you guys use to:
  14.  
  15.        a. Do a simple boolean test, like
  16.            if a=true    -or-   if a=false
  17.  
  18. As in LISP, use of the null value is common for this sort of value.
  19.         if \a then ... # if a is not null <==> if a is true
  20.         if /a then ... # if a is null <==> if a is false
  21. Note that most Icon-ers avoid "boolean variables" entirely when they can.
  22.  
  23.        b. Create something like a Pascal enumeration type
  24.           Days of the week, for example.  I create a list of strings:
  25.           ["Mon", "Tue", ...] but then I index it by a number (weekday[2]).
  26.           How would it be possible to index it as weekday[Tue]?
  27.  
  28. Two options come to mind, both dependent upon recent additions to Icon.
  29. I am not sure if they are both in 8.10; I think at least option #1 is.
  30.  
  31. Option #1 is to $define each value in your enumeration:
  32. $define Mon 1
  33. $define Tue 2
  34.  
  35. Option #2 is to define a record type
  36. record week(Mon,Tue,Wed,Thu,Fri,Sat,Sun)
  37.  
  38. then if weekday := week() you can say weekday.Mon or weekday["Mon"]
  39.  
  40.        c. initialize globals
  41.  
  42. There is no help for this and it is a deficiency in the language.
  43. How much is fixing it worth?  :-)
  44.  
  45. Clint Jeffery, jeffery@ringer.cs.utsa.edu, cjeffery@cs.arizona.edu
  46. U. of Texas at San Antonio
  47.